----------------------------------------------------------------
-- Scenario Exit Loading Screen
----------------------------------------------------------------

---------------------------------------------------------------------------------

function EA_Window_LoadingScreen.InitScenarioExitLoadScreen()

end

function EA_Window_LoadingScreen.BeginScenarioExitLoadScreen( loadingData)

    local scenarioId  = GameData.ScenarioData.id
    
    local windowName = "EA_Window_LoadingScreenScenarioExit"    
    local contentsWindowName = "EA_Window_LoadingScreenScenarioExitContents"

    -- Did the player Win??
    local playerWon = (GameData.Player.realm == GameData.Realms.REALM_ORDER and GameData.ScenarioData.orderPoints > GameData.ScenarioData.destructionPoints )
                        or (GameData.Player.realm == GameData.Realms.REALM_DESTRUCTION and GameData.ScenarioData.orderPoints < GameData.ScenarioData.destructionPoints )
                        
    local playerTied =  GameData.ScenarioData.orderPoints == GameData.ScenarioData.destructionPoints 		
    
    
    -- Set the winning labels & banners
    local realmColor = DataUtils.GetRealmColor (GameData.Realms.REALM_NEUTRAL)
    local largeText = GetString(StringTables.Default.TEXT_SCENARIO_TIE)
    local medText = L" "
    
    if (GameData.ScenarioData.orderPoints > GameData.ScenarioData.destructionPoints) then			
        realmColor	= DataUtils.GetRealmColor (GameData.Realms.REALM_ORDER)
        largeText	= GetString(StringTables.Default.LABEL_ORDER_ARMY)
        medText		= GetString(StringTables.Default.TEXT_SCENARIO_WIN)		
        
        WindowSetShowing(contentsWindowName.."OrderBanner1", true )
        WindowSetShowing(contentsWindowName.."OrderBanner2", true )
        WindowSetShowing(contentsWindowName.."DestructionBanner1", false )
        WindowSetShowing(contentsWindowName.."DestructionBanner2", false )	
        
    elseif (GameData.ScenarioData.orderPoints < GameData.ScenarioData.destructionPoints) then			
        realmColor = DataUtils.GetRealmColor (GameData.Realms.REALM_DESTRUCTION)
        largeText	= GetString(StringTables.Default.LABEL_DESTRUCTION_ARMY)
        medText		= GetString(StringTables.Default.TEXT_SCENARIO_WIN)			
        
        WindowSetShowing(contentsWindowName.."OrderBanner1", false )
        WindowSetShowing(contentsWindowName.."OrderBanner2", false )
        WindowSetShowing(contentsWindowName.."DestructionBanner1", true )
        WindowSetShowing(contentsWindowName.."DestructionBanner2", true )	
    
    else
        WindowSetShowing(contentsWindowName.."OrderBanner1", false )
        WindowSetShowing(contentsWindowName.."OrderBanner2", false )
        WindowSetShowing(contentsWindowName.."DestructionBanner1", false )
        WindowSetShowing(contentsWindowName.."DestructionBanner2", false )	
    end
    
    LabelSetTextColor (contentsWindowName.."StatusLarge", realmColor.r, realmColor.g, realmColor.b)		
    LabelSetTextColor (contentsWindowName.."StatusMedium", realmColor.r, realmColor.g, realmColor.b)
    LabelSetText (contentsWindowName.."StatusLarge", wstring.upper (largeText))
    LabelSetText (contentsWindowName.."StatusMedium", wstring.upper (medText))
        
        
    -- Size the Window Images to fit the Screen Height while keeping the same aspect ratio    
    local uiScale                   = InterfaceCore.GetScale()
    local screenWidth, screenHeight = GetScreenResolution()    
    local imageWidth, imageHeight   = WindowGetDimensions( contentsWindowName.."LeftImage" )
    
    imageWidth = (screenHeight/uiScale)*(imageWidth/imageHeight)
    imageHeight  = screenHeight/uiScale    
    
    WindowSetDimensions( contentsWindowName.."LeftImage", imageWidth, imageHeight ) 
    WindowSetDimensions( contentsWindowName.."RightImage", imageWidth, imageHeight ) 
    					
    
    
    -- Show the ScenarioSummaryWindow
    WindowSetShowing("ScenarioSummaryWindow", true )    
    ScenarioSummaryWindow.SetDisplayMode( ScenarioSummaryWindow.MODE_LOADING_SCREEN )
           

    local scoreWindow = "ScenarioSummaryWindow"

    local delay    = EA_Window_LoadingScreen.FADE_IN_TIME

    -- Fade in the Contents & Score Screen 
    WindowStartAlphaAnimation( contentsWindowName, Window.AnimationType.SINGLE, 0, 1, 
            EA_Window_LoadingScreen.FADE_IN_TIME, true, delay, 0 )
                        
    WindowStartAlphaAnimation( scoreWindow, Window.AnimationType.SINGLE, 0, 1, 
        EA_Window_LoadingScreen.FADE_IN_TIME, true, delay, 0 )
        
   -- Start Animating the Shield Glow
    WindowStartAlphaAnimation( windowName.."ShieldGlow", Window.AnimationType.LOOP, 0.1, 1.0, 0.75, false, delay, 0) 
    
end

function EA_Window_LoadingScreen.EndScenarioExitLoadScreen()

    local windowName = "EA_Window_LoadingScreenScenarioExit"    
    local contentsWindowName = "EA_Window_LoadingScreenScenarioExitContents"
    
    -- Fade out the contents
    WindowStartAlphaAnimation( contentsWindowName, Window.AnimationType.SINGLE_NO_RESET, 1, 0, 
              EA_Window_LoadingScreen.FADE_IN_TIME, true, 0, 0 )

    -- Stop Animating the Shield Glow
    WindowStopAlphaAnimation( windowName.."ShieldGlow" ) 
end

function EA_Window_LoadingScreen.StopScenarioExitLoadScreen()

    -- Restore the Frame to the ScenarioSummaryWindow    
     ScenarioSummaryWindow.SetDisplayMode( ScenarioSummaryWindow.MODE_IN_PROGRESS )
end